/**
 * Created by Amaris on 2016/12/5.
 */


var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 电话会议表
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'teleconference',
    tableName: 'tb_teleconference',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            unique: true,
            primaryKey: true,
            required: true,
            columnName: 'rowid',
            uuidv4: true,
            defaultsTo: function() {
                return uuid.v4();
            }
        },
        seller: {
            type: 'string',
            required: true,
            columnName: 'seller',
            model: 'seller'
        },
        industry: {
            type: 'string',
            required: true,
            columnName: 'industry',
            model: 'industry'
        },
        startTime: {
            type: 'datetime',
            required: true,
            before: function() {
                return this.finishTime;
            },
            columnName: 'starttime'
        },
        finishTime: {
            type: 'datetime',
            required: true,
            after: function() {
                return this.startTime;
            },
            columnName: 'finishtime'
        },
        type: {
            type: 'string',
            required: true,
            columnName: 'type'
        },
        content: {
            type: 'string',
            columnName: 'content'
        },
        range: {
            type: 'string',
            required: true,
            columnName: 'range'
        },
        contact:{
            type: 'string',
            required: true,
            columnName: 'contact'
        },
        password:{
            type: 'string',
            required: true,
            columnName: 'password'
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid',
            model: 'user'
        },
        score: {
            type: 'string',
            columnName: 'score'
        },
        scoreUid: {
            type: 'string',
            columnName: 'scoreuid',
            model: 'user'
        },
        scoreTime: {
            type: 'datetime',
            columnName: 'scoretime'
        },
        company:{
            type: 'string',
            columnName: 'company',
            model: 'dic_stock'
        },
        /**
         * 2017年04月14日新增
         */
        teamId:{
            type: 'string',
            columnName: 'teamid'
        },
        toJSON: function() {
            var obj = this.toObject();
            obj.scoreTime=moment(obj.scoreTime).format('YYYY/MM/DD hh:mm');
            obj.startTime=moment(obj.startTime).format('YYYY/MM/DD hh:mm');
            obj.finishTime=moment(obj.finishTime).format('YYYY/MM/DD hh:mm');
            obj.createdAt=moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt=moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');

            return obj;
        }
    }
});
